package com.ms.education.course.controller;

import com.ms.education.R;
import com.ms.education.course.entity.Video;
import com.ms.education.course.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author ms
 * @since 2023-01-18
 */
@RestController
@RequestMapping("/course/video")
public class VideoController {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    private VideoService videoService;

    @PostMapping("saveOrUpdateVideo")
    public R saveOrUpdateVideo(@RequestBody Video video) {
        videoService.saveOrUpdate(video);
        return R.ok();
    }

    @DeleteMapping("deleteVideoById")
    public R deleteVideoById(Video video) {
        videoService.deleteVideoById(video);
        return R.ok();
    }

    @GetMapping("getVideoById/{id}")
    public R getVideoById(@PathVariable("id") Integer id) {
        Video video = videoService.getById(id);
        return R.ok().data("video", video);
    }

    //获取视频播放数
    @PostMapping("getVideoPlayNums")
    public R getVideoPlayNums(String[] videoSourceIds) {
        Map<String, Integer> res = videoService.getVideoPlayNums(videoSourceIds);
        return R.ok().data("res", res);
    }

}
